package cn.edu.ustc.xrovers.daoImpl;

import java.sql.SQLException;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;

import cn.edu.ustc.xrovers.dao.LoanIndexDao;
import cn.edu.ustc.xrovers.model.NonFinancialInfoRatio;
import cn.edu.ustc.xrovers.model.ProcessedStatement;

public class LoanIndexDaoImpl extends BaseDao implements LoanIndexDao{

	public NonFinancialInfoRatio findQualitativeIndex(final String companyId, final int year) {
		return ht.execute(new HibernateCallback<NonFinancialInfoRatio>() {
			public NonFinancialInfoRatio doInHibernate(Session session) throws HibernateException,
					SQLException {
				Query query=session.createQuery("from NonFinancialInfoRatio nfir where nfir.nfi.company.companyId=:companyId and nfir.nfi.year=:year");
				query.setParameter("companyId", companyId);
				query.setParameter("year", year);
				return (NonFinancialInfoRatio) query.uniqueResult();
			}
		});
	}
	
	public ProcessedStatement findQuantitativeIndex(final String companyId, final int year) {
		return ht.execute(new HibernateCallback<ProcessedStatement>() {
			public ProcessedStatement doInHibernate(Session session)
					throws HibernateException, SQLException {
				Query query=session.createQuery("from ProcessedStatement ps where ps.company.companyId=:companyId and ps.year=:year");
				query.setParameter("companyId", companyId);
				query.setParameter("year", year);
				return (ProcessedStatement) query.uniqueResult();
			}
		});
	}
}
